import redis as origin_redis


class Redis(object):
    def __init__(self, host='127.0.0.1', port=6379):
        self.client = origin_redis.Redis(host=host, port=port, db=0, decode_responses=True)

    def save(self, key, value, name=''):
        if name:
            return self.client.hset(key, name, value) == 1
        return self.client.set(key, value) == 1

    def delete(self, key, name=''):
        if name:
            return self.client.hdel(key, name)
        return self.client.delete(key)

    def get(self, key, name=''):
        if name:
            return self.client.hget(key, name)
        return self.client.get(key)


redis = Redis()